<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

	class Admin_model extends CI_Controller {

	/**
	 * Index Page for this controller.
	 *
	 * Maps to the following URL
	 * 		http://example.com/index.php/welcome
	 *	- or -  
	 * 		http://example.com/index.php/welcome/index
	 *	- or -
	 * Since this controller is set as the default controller in 
	 * config/routes.php, it's displayed at http://example.com/
	 *
	 * So any other public methods not prefixed with an underscore will
	 * map to /index.php/welcome/<method_name>
	 * @see http://codeigniter.com/user_guide/general/urls.html
	 */


	public function addAccount($id){
		$q = "SELECT email_address,password FROM student WHERE student_no like '".$id."'";
		$query = $this->db->query($q);
		foreach ($query->result() as $row)
		{
			$in = "INSERT into accounts_active values('".
				   $row->email_address."','".
				   $row->password."','".
				   md5($row->email_address)."','student')";
			
			$query = $this->db->query($in);
			
			$out = "UPDATE student SET approved = 'Approved' WHERE student_no like '".$id."'";
			$query = $this->db->query($out);
			redirect('home/admin','');
			}
		}
	
	public function list_all_accounts(){
		$q = "SELECT * from accounts_active";
		$query = $this->db->query($q);
		var_dump($query);
	}

	public function deactivate_account($id){
		//put a deactivate something in the toilet
	}

	public function disapprove($id){
		if(strlen($id)=='10'){
			$q = "UPDATE student set Approved = 'Disapproved' where student_no like '".$id."'";
			$this->db->query($q);
			redirect('home/admin','');
		}
		else if(strlen($id)=='9'){
			$q = "UPDATE instructor set Approved = 'Disapproved' where student_no like '".$id."'";
			$this->db->query($q);
			redirect('home/admin','');
		}
	}

	public function addInstructorAccount($id){
		$q = "SELECT email_address,password FROM instructor WHERE employee_no like '".$id."'";
		$query = $this->db->query($q);
		foreach ($query->result() as $row)
		{
			$in = "INSERT into accounts_active values('".
				   $row->email_address."','".
				   $row->password."','".
				   md5($row->email_address)."','instrutor')";
			
			$query = $this->db->query($in);
			
			$out = "UPDATE instructor SET approved = 'Approved' WHERE employee_no like '".$id."'";
			$query = $this->db->query($out);
			redirect('home/admin','');
		}
	}

	public function update_log($message,$user){
		//id dapat ng lahat ng users dapat yung parameter ng user
		$this->load->helper('date');
		$data = array(
				'ACTIVITY' => $message,
				'USER_INVOLVED' => $user
			);

	$this->db->insert('log',$data);
	}
}
/* End of file user_model.php */
/* Location: ./application/controllers/user_model.php */